/*
 * @Author: your name
 * @Date: 2021-04-23 16:14:11
 * @LastEditTime: 2021-04-24 22:52:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \hello-world\src\router\index.js
 */

import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/login'

  },
  {
    path: '/login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/home',
    //   name: 'About',
    component: () => import( /* webpackChunkName: "about" */ '@/components/Home.vue'),
    redirect: '/Welcome',
    children: [{
        path: '/Welcome',
        component: () => import('@/components/inden/Welcome.vue')
      },
      {
        path: '/users',
        component: () => import('@/components/user/Users.vue')
      },
      {
        path: '/rights',
        component: () => import('../components/power/Rights.vue')
      },
      {
        path: '/roles',
        component: () => import('../components/power/Roles.vue')
      },
      {
        path: '/categories',
        component: () => import('../components/goods/Cate.vue')
      },
      {
        path: '/params',
        component: () => import('../components/goods/Params.vue')
      },


    ]
  }

]

const router = new VueRouter({
  routes
})
// 配置路由守卫
router.beforeEach((to, from, next) => {
  // 如果访问登陆页，则放行
  if (to.path === '/login') {
    return next()
  }
  // 如果用户未登陆，则跳转到/login
  const userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
  if (!userInfo) {
    return next('/login')
  }
  // 如果用户已登陆，则放行
  next()
})

export default router